home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / ARMTEX / SOURCES1 / !TeX / texmf / source / armTeX / lib / h / lib < prev    next >
Encoding:
Text File  |  1993-04-30  |  5.2 KB  |  126 lines

  1. /* lib.h: declarations for shared routines.
  2.  
  3. Copyright (C) 1992, 93 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef LIB_H
  20. #define LIB_H
  21.  
  22. #include "types.h"
  23.  
  24. /* Define common sorts of messages.  */
  25.  
  26. /* This should be called only after a system call fails.  */
  27. #define FATAL_PERROR(s) do { perror (s); exit (errno); } while (0)
  28.  
  29.  
  30. #define START_FATAL() do { fputs ("fatal: ", stderr)
  31. #define END_FATAL() fputs (".\n", stderr); exit (1); } while (0)
  32.  
  33. #define FATAL(str)                                                      \
  34.   START_FATAL (); fprintf (stderr, "%s", str); END_FATAL ()
  35. #define FATAL1(str, e1)                                                 \
  36.   START_FATAL (); fprintf (stderr, str, e1); END_FATAL ()
  37. #define FATAL2(str, e1, e2)                                             \
  38.   START_FATAL (); fprintf (stderr, str, e1, e2); END_FATAL ()
  39. #define FATAL3(str, e1, e2, e3)                                         \
  40.   START_FATAL (); fprintf (stderr, str, e1, e2, e3); END_FATAL ()
  41. #define FATAL4(str, e1, e2, e3, e4)                                     \
  42.   START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4); END_FATAL ()
  43.  
  44.  
  45. #define START_WARNING() do { fputs ("warning: ", stderr)
  46. #define END_WARNING() fputs (".\n", stderr); fflush (stderr); } while (0)
  47.  
  48. #define WARNING(str)                                                    \
  49.   START_WARNING (); fprintf (stderr, "%s", str); END_WARNING ()
  50. #define WARNING1(str, e1)                                               \
  51.   START_WARNING (); fprintf (stderr, str, e1); END_WARNING ()
  52. #define WARNING2(str, e1, e2)                                           \
  53.   START_WARNING (); fprintf (stderr, str, e1, e2); END_WARNING ()
  54. #define WARNING3(str, e1, e2, e3)                                       \
  55.   START_WARNING (); fprintf (stderr, str, e1, e2, e3); END_WARNING ()
  56. #define WARNING4(str, e1, e2, e3, e4)                                   \
  57.   START_WARNING (); fprintf (stderr, str, e1, e2, e3, e4); END_WARNING ()
  58.  
  59. /* I find this easier to read.  */
  60. #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
  61.  
  62. /* This is the maximum number of numerals that result when a 64-bit
  63.    integer is converted to a string, plus one for a trailing null byte,
  64.    plus one for a sign.  */
  65. #define MAX_INT_LENGTH 21
  66.  
  67. /* Return a fresh copy of S1 followed by S2, et al.  */
  68. extern string concat P2H(string s1, string s2);
  69. extern string concat3 P3H(string, string, string);
  70. extern string concat4 P4H(string, string, string, string);
  71. extern string concat5 P5H(string, string, string, string, string);
  72.  
  73.  
  74. /* A fresh copy of just S.  */
  75. extern string xstrdup P1H(string s);
  76.  
  77.  
  78. /* True if FILENAME1 and FILENAME2 are the same file.  If stat fails on
  79.    either name, returns false, with no error message.  */
  80. extern boolean same_file_p P2H(string filename1, string filename2);
  81.  
  82.  
  83. /* If NAME has a suffix, return a pointer to its first character (i.e.,
  84.    the one after the `.'); otherwise, return NULL.  */
  85. extern string find_suffix P1H(string name);
  86.  
  87. /* Return NAME with any suffix removed.  */
  88. extern string remove_suffix P1H(string name);
  89.  
  90. /* Return S with the suffix SUFFIX, removing any suffix already present.
  91.    For example, `make_suffix ("/foo/bar.baz", "karl")' returns
  92.    `/foo/bar.karl'.  Returns a string allocated with malloc.  */
  93. extern string make_suffix P2H(string s, string suffix);
  94.  
  95. /* Return NAME with STEM_PREFIX prepended to the stem. For example,
  96.    `make_prefix ("/foo/bar.baz", "x")' returns `/foo/xbar.baz'.
  97.    Returns a string allocated with malloc.  */
  98. extern string make_prefix P2H(string stem_prefix, string name);
  99.  
  100. /* If NAME has a suffix, simply return it; otherwise, return
  101.    `NAME.SUFFIX'.  */
  102. extern string extend_filename P2H(string name, string suffix);
  103.  
  104.  
  105. /* Like their stdio counterparts, but abort on error, after calling
  106.    perror(3) with FILENAME as its argument.  */
  107. extern FILE *xfopen P2H(string filename, string mode);
  108. extern void xfclose P2H(FILE *, string filename);
  109. extern void xfseek P4H(FILE *, long, int, string filename);
  110. extern long xftell P2H(FILE *, string filename);
  111.  
  112.  
  113. /* These call the corresponding function in the standard library, and
  114.    abort if those routines fail.  Also, `xrealloc' calls `xmalloc' if
  115.    OLD_ADDRESS is null.  */
  116. extern address xmalloc P1H(unsigned size);
  117. extern address xrealloc P2H(address old_address, unsigned new_size);
  118. extern address xcalloc P2H(unsigned nelem, unsigned elsize);
  119.  
  120. /* (Re)Allocate N items of type T using xmalloc/xrealloc.  */
  121. #define XTALLOC(n, t) (t *) xmalloc ((n) * sizeof (t))
  122. #define XTALLOC1(t) XTALLOC (1, t)
  123. #define XRETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof(t)))
  124.  
  125. #endif /* not LIB_H */
  126.